<?php

use App\Http\Controllers\AuthController;
use App\Http\Controllers\GoodsController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\OrderController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\CommonController;

Route::group(['prefix' => 'auth'], function () {
    Route::post('login', [AuthController::class, 'login']);
    Route::post('register', [AuthController::class, 'register']);
    Route::post('sendCode', [AuthController::class, 'sendCode']);

    Route::group(['middleware' => 'jwt.verify'], function () {
        Route::post('logout', [AuthController::class, 'logout']);
        Route::post('user', [AuthController::class, 'user']);
    });
});

Route::group(['prefix' => 'user'],function (){

    Route::group(['middleware' => 'jwt.verify'], function () {
        Route::post('addressList', [UserController::class, 'addressList']);
        Route::post('addAddress', [UserController::class, 'addAddress']);
        Route::post('updateAddress', [UserController::class, 'updateAddress']);
        Route::post('removeAddress', [UserController::class, 'removeAddress']);
        Route::post('setDefaultAddress', [UserController::class, 'setDefaultAddress']);
        Route::post('addressDetail', [UserController::class, 'addressDetail']);
    });
});

Route::group(['prefix' => 'goods'],function (){
    Route::post('list',[GoodsController::class,'list']);
    Route::post('detail',[GoodsController::class,'detail']);


    Route::group(['middleware' => 'jwt.verify'], function () {
        Route::post('addCart', [GoodsController::class, 'addCart']);
        Route::post('removeCart', [GoodsController::class, 'removeCart']);
        Route::post('shopCartList', [GoodsController::class, 'shopCartList']);
    });
});

Route::group(['prefix' => 'order','middleware' => 'jwt.verify'],function (){
    Route::post('cashDesk', [OrderController::class, 'cashDesk']);
    Route::post('removeCart', [GoodsController::class, 'removeCart']);
    Route::post('shopCartList', [GoodsController::class, 'shopCartList']);
    Route::post('createOrder', [OrderController::class, 'createOrder']);
    Route::post('list', [OrderController::class, 'list']);
    Route::post('detail', [OrderController::class, 'detail']);
});

Route::any('upload', [CommonController::class, 'upload']);


// 需要认证的路由
Route::group(['middleware' => 'jwt.verify'], function () {
    // 在这里添加需要认证的路由
    Route::get('/protected', function () {
        return response()->json(['message' => '这是受保护的接口']);
    });
});
